package com.ctshk.common.enums;

import java.util.Arrays;
import java.util.Objects;

/**
 * <p>
 *  币种枚举
 * </p>
 *
 * @author 胡广
 * @since 2021/2/26
 */
public enum Currency {
    HKD(1365184144700788737L,"HKD","HK$"),
    CNY(1364538230965456898L, "CNY", "￥"),
    USD(1355123737372696577L, "USD", "$");

    private Long id;
    private String currency;
    private String symbol;

    Currency(Long id, String currency, String symbol) {
        this.id = id;
        this.currency = currency;
        this.symbol = symbol;
    }

    public Long getCode() {
        return id;
    }

    public void setCode(Long id) {
        this.id = id;
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public String getSymbol() {
        return symbol;
    }

    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    public static Currency getCurrencyById(long id) {
        return Arrays.stream(Currency.values())
                .filter(enums -> Objects.equals(enums.getCode(), id))
                .findFirst().orElse(null);
    }

    public static Currency getCurrencyByCurrency(String currency) {
        return Arrays.stream(Currency.values())
                .filter(enums -> Objects.equals(enums.getCurrency(), currency))
                .findFirst().orElse(null);
    }
}
